package com.bort.system.utils;

import lombok.Data;

import java.util.List;

/*
 * 分页类
 */
@Data
public class Pager<T> {

    private Object condition;

    private int currentPage;

    private int totalRow;

    private int totalPages;

    private int rowSize = 12;

    private List<T> list;

    private int offset;

    public void setTotalRow(int totalRow) {
        this.totalRow = totalRow;
        int pages = totalRow / rowSize;
        if (pages * rowSize < totalRow) {
            pages++;
        }
        this.totalPages = pages;
    }

    public void setCurrentPage(int currentPage) {
        if (currentPage <= 1) {
            currentPage = 1;
        }
        this.currentPage = currentPage;
        this.offset = (this.currentPage - 1) * this.rowSize;
    }

    public void setRowSize(int rowSize) {
        this.rowSize = rowSize;
        if (this.currentPage > 0) {
            this.offset = (this.currentPage - 1) * this.rowSize;
        }
    }
}
